package cn.stylefeng.guns.modular.cangku.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;

import cn.stylefeng.guns.modular.system.model.Educationtype;
import cn.stylefeng.guns.modular.system.model.Storehouse;
import cn.stylefeng.guns.modular.cangku.service.IStorehouseService;

/**
 * 书刊仓库控制器
 *
 * @author fengshuonan
 * @Date 2020-06-23 00:09:22
 */
@Controller
@RequestMapping("/storehouse")
public class StorehouseController extends BaseController {

    private String PREFIX = "/cangku/storehouse/";

    @Autowired
    private IStorehouseService storehouseService;

    /**
     * 跳转到书刊仓库首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "storehouse.html";
    }

    /**
     * 跳转到添加书刊仓库
     */
    @RequestMapping("/storehouse_add")
    public String storehouseAdd() {
        return PREFIX + "storehouse_add.html";
    }

    /**
     * 跳转到修改书刊仓库
     */
    @RequestMapping("/storehouse_update/{storehouseId}")
    public String storehouseUpdate(@PathVariable Integer storehouseId, Model model) {
        Storehouse storehouse = storehouseService.selectById(storehouseId);
        model.addAttribute("item",storehouse);
        LogObjectHolder.me().set(storehouse);
        return PREFIX + "storehouse_edit.html";
    }
    
    /**
     * 跳转到出库书刊仓库
     */

    @RequestMapping("/storehouse_chu/{storehouseId}")
    public String storehouseChu(@PathVariable Integer storehouseId, Model model) {
        Storehouse storehouse = storehouseService.selectById(storehouseId);
        model.addAttribute("item",storehouse);
        LogObjectHolder.me().set(storehouse);
        return PREFIX + "storehouse_chu.html";
    }
    
    /**
     * 跳转到入库书刊仓库
     */

    @RequestMapping("/storehouse_join/{storehouseId}")
    public String storehouseJoin(@PathVariable Integer storehouseId, Model model) {
        Storehouse storehouse = storehouseService.selectById(storehouseId);
        model.addAttribute("item",storehouse);
        LogObjectHolder.me().set(storehouse);
        return PREFIX + "storehouse_join.html";
    }

    
    
    /**
     * 获取书刊仓库列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Storehouse> wrapper = new EntityWrapper<Storehouse>();
    	wrapper.like("goods_name" ,condition).or()
    	.like("id", condition)	;
        return storehouseService.selectList(wrapper);
    }
    
    /**
     * 获取书刊仓库列表
     */
//    @RequestMapping(value = "/list")
//    @ResponseBody
//    public Object list2(String condition) {
//    	EntityWrapper<Storehouse> wrapper = new EntityWrapper<Storehouse>();
//	   wrapper.like("id" ,condition);
//	 return storehouseService.selectList(wrapper);
//    }
    /**
     * 新增书刊仓库
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Storehouse storehouse) {
        storehouseService.insert(storehouse);
        return SUCCESS_TIP;
    }

    /**
     * 删除书刊仓库
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer storehouseId) {
        storehouseService.deleteById(storehouseId);
        return SUCCESS_TIP;
    }

    /**
     * 修改书刊仓库
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Storehouse storehouse) {
        storehouseService.updateById(storehouse);
        return SUCCESS_TIP;
    }
    
    @RequestMapping(value = "/chu")
    @ResponseBody
    public Object chu(Storehouse storehouse) {
        storehouseService.updateById(storehouse);
        return SUCCESS_TIP;
    }
    
    @RequestMapping(value = "/join")
    @ResponseBody
    public Object join(Storehouse storehouse) {
        storehouseService.updateById(storehouse);
        return SUCCESS_TIP;
    }

    /**
     * 书刊仓库详情
     */
    @RequestMapping(value = "/detail/{storehouseId}")
    @ResponseBody
    public Object detail(@PathVariable("storehouseId") Integer storehouseId) {
        return storehouseService.selectById(storehouseId);
    }
}
